package com.example.dell.test1;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

/**
 * Created by klren on 2016/6/1.
 */
public class zhuceActivity extends Activity {
    Button zhuce;
    EditText name;
    EditText pwd;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhuce);
        btnThings();
    }

    private void btnThings(){
        zhuce = (Button) findViewById(R.id.zcBtn);
        name = (EditText)findViewById(R.id.name);
        pwd = (EditText)findViewById(R.id.pwd);


        /**
         * 注册按钮点击事件，进行账号注册，用户名密码存入sqlit数据库
         */
        zhuce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UserService US = new UserService(zhuceActivity.this);
                User user = new User();
                user.setUsername(name.getText().toString().trim());// Trim()用来去掉两边空格
                user.setPassword(pwd.getText().toString().trim());
                US.register(user);
                Toast.makeText(zhuceActivity.this,"注册成功",Toast.LENGTH_LONG).show();
                Intent intent = new Intent(zhuceActivity.this,MainActivity.class);
                startActivity(intent);
            }
        });
    }
}
